import Util from "../../../../utils/util2"
import config from "../../../../utils/config2"
var regeneratorRuntime = require("../../../../lib/js/runtime-module.js")
import Serv from './gameTransferStationServ';

var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    preInfo:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _this = this
    let userData = wx.getStorageSync('userData')
    if(options.scene){
      this.sceneParamGet(options.scene)
      return;
    }
    if(!userData){
      Util.clearStorage(config.retainKey)
      options = JSON.stringify(options)

      wx.redirectTo({
        url:`/subPackages/pages/login/login?targetType=game&gameOptions=${options}`
      })
      return
    }


    
    // let {gameActivityId,helpPamars,type} = options
    
    // let gameInfo = wx.getStorageSync('gameInfo')
    // wx.setStorageSync('gameInfo',{...gameInfo,...options})
    
    // app.globalData.gameInfo={...options}
    // console.log(app.globalData.gameInfo)
    // if(!userData){
    //   Util.clearStorage(config.retainKey)
    //   options = JSON.stringify(options)

    //   wx.navigateTo({
    //     url:`/subPackages/pages/login/login?targetType=game&gameOptions=${options}`
    //   })
    //   return
    // }
    // if(gameInfo.scene){
      
    //   this.sceneParamGet(gameInfo.scene)
    // }
    

      if(options.routerType=='login'){
        let optionss = JSON.parse(options.options)
        if(optionss.scene){
          this.sceneParamGet(optionss.scene)
        }else{
          wx.redirectTo({
            url:`/subPackages3/pages/gameManage/gameIndex/gameIndex?options=${options.options}&routerType=${options.routerType}`
          })
        }
        
      }else if(options.actionType=='help'){
        // Util.clearStorage(config.retainKey)
        // options = JSON.stringify(options)

        // wx.navigateTo({
        //   url:`/subPackages/pages/login/login?targetType=game&gameOptions=${options}`
        // })
        // return
        wx.redirectTo({
          url:`/subPackages3/pages/gameManage/gameIndex/gameIndex?helpPamars=${options.helpPamars}&actionType=${options.actionType}`
        })
  
      }else{
        console.log(options)
        wx.redirectTo({
          url:`/subPackages3/pages/gameManage/gameIndex/gameIndex?gameActivityId=${options.gameActivityId}`
        })
      }
      // if(type=='help'){
      //   _this.setData({
      //     type:type||''
      //   })
      // }

      // if(wx.getStorageSync('gameInfo').gameActivityId&&!pamars&&options!='{}'){
      //   wx.redirectTo({
      //     url:`/subPackages3/pages/gameManage/gameIndex/gameIndex?gameActivityId=${wx.getStorageSync('gameInfo').gameActivityId}`
      //   })
      // }
      // if(pamars){
      //   let pamars2 = JSON.parse(pamars)
      //   let pamars3 =pamars2 || JSON.parse(gameInfo.pamars)
      //   pamars3 = {...pamars3}
      //   console.log(pamars3)
      //   let pamars4 = JSON.stringify(pamars3)
      //   wx.redirectTo({
      //     url:`${pamars3.target}?pamars=${pamars4}`
      //   })
      // }
      // if(options=='{}'){
      //   let pamars = JSON.parse(gameInfo.pamars)
      //   if(pamars.target){
      //     wx.redirectTo({
      //       url:`${pamars.target}?parmas=${gameInfo.pamars}`
      //     })
      //   }
      // }
    
    
  },
  async sceneParamGet(scene){
    let {success,data} = await Serv.sceneParamGet({scene:scene})
    console.log(data)
    if(success){
      // let {gameActivityId,actionType,targetPage} = data.params
      let {nickname,mobilePhone,gameActivityId,actionType} = data.params
      const params = data.params
     
      if(params.accountId&&(params.accountId>=1&&params.accountId<=15)){
        params.recommendType = 3
      }
      wx.setStorageSync(config.referrerIdKey, params.userId)
      wx.setStorageSync(config.referrerPhone,params.recommendPhone)
      wx.setStorageSync(config.referrerType,params.recommendType)
      wx.setStorageSync(config.referrerProductId,params.productId)
      if(actionType=='help'){
        let helpPamars = {
          nickname:nickname,
          mobilePhone:mobilePhone,
          gameActivityId:gameActivityId
        }
        helpPamars = JSON.stringify(helpPamars)
        wx.redirectTo({
          url:`/subPackages3/pages/gameManage/gameIndex/gameIndex?actionType=help&helpPamars=${helpPamars}`
        })
      }else{
        console.log(gameActivityId)
        wx.redirectTo({
          url:`/subPackages3/pages/gameManage/gameIndex/gameIndex?gameActivityId=${gameActivityId}`
        })
      }
      

      // let gameInfo = wx.getStorageSync('gameInfo')
      // wx.setStorageSync('gameInfo',{...gameInfo,...data.params.params})
      
      

     
      // wx.redirectTo({
      //   url:`/subPackages3/pages/gameManage/gameIndex/gameIndex?gameActivityId=${data.params.params.gameActivityId}?type=help`
      // })
    }
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})